# -*- coding: utf-8 -*-
# Created Time : 2022/1/5 15:50
# Author:Zhou
import os
import h5py
import numpy as np
from ANC_tools import sin_wave, awgn, NPP_1,NPP_2,NPP_3,NPP_4,NPP_5, logisticChaotic

# 生成交叉验证数据
# some settings
rms = 1.0
filepath = 'datasets/cv/'
filename = 'cv.ex'
n_cv_ex = 1
writer = h5py.File(os.path.join(filepath, filename), 'w')
for idx in range(n_cv_ex):
    # generate a noisy mixture
    # 和训练集 测试集的一样
    mix = sin_wave(A=1, f=100, fs=16000, phi=0, t=1) \
          + sin_wave(A=1, f=100, fs=16000, phi=90, t=1) \
          + sin_wave(A=0.0, f=200, fs=16000, phi=180, t=1)
    # mix = awgn(mix, 40)
    # mix = logisticChaotic(0.9, 4, 48000)
    # sph = NPP_1(mix)
    sph = sin_wave(A=1, f=100, fs=16000, phi=0, t=1)
    # normalize
    c = rms * np.sqrt(mix.size / np.sum(mix ** 2))
    mix *= c
    sph *= c

    # 新建组
    writer_grp = writer.create_group(str(idx))
    writer_grp.create_dataset('mix', data=mix.astype(np.float32), shape=mix.shape, chunks=True)
    writer_grp.create_dataset('sph', data=sph.astype(np.float32), shape=sph.shape, chunks=True)
writer.close()
